import axios from "axios";

export const findCustomersByName = (name, cb) => {
    axios.get('/customer/find', {params: {name: name}}).then((response) => {
        for (const cus of response.data) {
            cus.value = cus.name
        }
        cb(response.data);
    })
}

export const getCustomer = (id, callback) => {
    axios.get('/customer/' + id).then((response) => {
        callback(response.data)
    })
}

export const getCustomerList = (callback) => {
    axios.get('/customer').then((response) => {
        callback(response.data);
    });
}


export const deleteCustomer = (id, callback) => {
    axios.delete('/customer/' + id).then((response) => {
        callback(response.data);
    });
}

export const updateCustomer = (customerData, callback) => {
    axios.put('/customer/' + customerData.oid, customerData).then((response) => {
        callback(response.data ? 1 : 0);
    })
}

export const createCustomer = (customerData, callback) => {
    axios.post('/customer', customerData).then((response) => {
        callback(response.data ? 1 : 0)
    })
}